package com.dzl.base.service.impl;

import com.dzl.base.dao.BaseDataMapper;
import com.dzl.base.pojo.BaseData;
import com.dzl.base.service.BaseDataService;
import com.dzl.base.service.BaseServiceImpl;
// import com.dzl.constant.BaseDataConstant;
import com.dzl.constant.CommonConstants;
import com.dzl.util.EmptyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.util.Sqls;

import java.util.List;

/**
 * 系统基础数据表(BaseData)表服务实现类
 *
 * @author lishunxing
 * @date 2021-03-01 11:21:31
 */
@Service
public class BaseDataServiceImpl extends BaseServiceImpl<BaseData> implements BaseDataService {

    @Autowired
    private BaseDataMapper mapper;

    @Override
    public List<BaseData> findListByCode(String code) {
        Example example = Example.builder(BaseData.class).where(Sqls.custom().andNotEqualTo("parentId", 0)
                .andEqualTo("code", code)
                .andEqualTo("status", 1)).build();
        return mapper.selectByExample(example);
    }

    @Override
    public BaseData findByCode(String code) {
        BaseData query = new BaseData();
        query.setCode(code);
        query.setStatus(CommonConstants.YES);
        List<BaseData> list = mapper.select(query);
        return EmptyUtils.isNotEmpty(list)?list.get(0):null;
    }
}
